package com.yibo.yunpicture.infrastructure.common;

import com.yibo.yunpicture.infrastructure.exception.ErrorCode;
import lombok.Data;

import java.io.Serializable;

/**
 * 全局响应封装类
 *
 * @param <T>
 */
@Data
public class BaseResponse<T> implements Serializable {
    private int code;
    private T data;
    private String message;

    public BaseResponse(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(int code,T data) {
        this.code = code;
        this.data = data;
        this.message = "";
    }

    // 构造函数，传入一个ErrorCode参数
    public BaseResponse(ErrorCode errorCode) {
        // 调用父类的构造函数，传入errorCode的code、null和message
        this(errorCode.getCode(),null,errorCode.getMessage());
    }
}
